package com.jf.docsify.common.init.db;

import java.io.File;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.jf.docsify.common.annotation.DbType;
import com.jf.docsify.common.enums.EnumDbType;
import com.jf.docsify.common.exception.DocsifyException;
import com.jf.docsify.common.utils.FileUtil;
import com.jf.docsify.common.utils.SystemUtil;
import com.jf.docsify.config.DocsifyConfig;

@DbType(EnumDbType.SQLITE)
public class SqliteDbInit extends DbInitBaseService implements DbInitService {

    @Override
    protected void init() {
        createTable();
    }

    @Override
    protected String formatUrl(String url) {
        String sqliteDbFilePath = DocsifyConfig.getSqliteDbFilePath(url);
        return "jdbc:sqlite:" + sqliteDbFilePath;
    }

    @Override
    protected String sqlScriptName() {
        return "init/db/docsify-sqlite.sql";
    }

    @Override
    protected List<String> showTables() {
        return execSqlCommand("select name from sqlite_master where type='table' order by name");
    }

    @Override
    protected List<String> ignoreCreateTables() {
        return new ArrayList<String>(){{
            add("sqlite_sequence");
        }};
    }

    @Override
    protected String driver() {
        return "org.sqlite.JDBC";
    }
}
